define(["app","js/services/MuseService",'js/services/MessageBox'],
    function (app) {
        var deps = ["$scope", "$http", "$rootScope", "$filter", "$state", "$stateParams","MuseService","MessageBox"];

        function controller($scope, $http, $rootScope, $filter, $state, $stateParams,MuseService,MessageBox) {
            $scope.curUser = getSessionJson('curUserObj');

            if(isEmpty($scope.curUser)){
                var url = 'login.html';
                location.replace(url);
            }

            $scope.owner = {};
            // 是否编辑
            $scope.isEdit = false;

            $scope.getDriverDetail = function() {
                MuseService.post("owner/getOwnerDetailByUser/"+$scope.curUser.id, {

                }).success(function(data) {
                    if (data.code == 0) {
                        $scope.owner = data.data;
                    } else {
                        MessageBox.error("查询失败:" + data.msg);
                    }
                });
            };

            $scope.getDriverDetail();

            $scope.delOwner = function(){
                MuseService.post("check/ownerpushdel", {id:$scope.owner.id}).success(function(data) {
                    if (data.code == 0) {
                        MessageBox.notify("保存成功！");
                        history.back();
                    } else {
                        MessageBox.error("保存失败: " + data.msg);
                    }
                });
            }

            // 保存发现 基本信息
            $scope.saveObj = function() {
                MuseService.postObj("owner/saveOwner/"+$scope.curUser.id , $scope.owner).success(function(data) {
                    if (data.code == 0) {
                        MessageBox.notify("保存成功！");
                        history.back();
                    } else {
                        MessageBox.error("保存失败: " + data.msg);
                    }
                });
            };

        }

        controller.$inject = deps;
        app.lazy.controller("OwnerDetailController", controller);
    });